import net.chrisrichardson.ec2deployer.cluster.ClusterManager

pluginHome = new File("./plugins").listFiles().find { it.name.startsWith('cloud-tools-')}
if(pluginHome == null) pluginHome = "."

includeTargets << new File("${pluginHome}/scripts/ExplodedWar.groovy")
includeTargets << new File("${pluginHome}/scripts/CloudToolsInit.groovy")

target('default': "Deploy to EC2") {
    deploy()
}

target(deploy: "The implementation task") {
    depends(explodedWar, initCloudToolsService)

    Ant.replace(file: "explodedWar/${grailsAppName}/WEB-INF/web.xml", token: "log4jConfigLocation", value: "log4jConfigLocationCloudToolsPluginUtil")
    event("StatusUpdate", ["Deploying cluster"])

    cloudToolsService.withClusterManager {clusterManager, clusterName ->
        clusterManager.defineCluster(clusterName, cloudToolsService.makeClusterSpec(grailsAppName));
        clusterManager.startCluster(clusterName);
    }

    event("StatusFinal", ["Finished deploying cluster"])
}


